;(() => {
  const { userAgent } = window.navigator;
  const ios = !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  let timeout: any;

  if (ios) {
    window.document.body.addEventListener('focusin', () => {
      window.clearTimeout(timeout);
    });
    window.document.body.addEventListener('focusout', () => {
      window.clearTimeout(timeout);
      timeout = window.setTimeout(() => {
        window.scrollTo({
          top: 0,
          left: 0,
          behavior: 'smooth',
        });
      }, 0);
    });
  }
})();
